<template>
	<view class="wrap">
		<!-- <u-navbar  :borderBottom="false" :background="{'color':'#fff'}" title="剑未配妥，出门已是江湖"
			 ></u-navbar> -->
		<u-navbar :is-back="false" :borderBottom="false" title="" title-color="#000" :title-bold="true"></u-navbar>
		<view class="top"></view>
		<view class="content">
			<view class="title">欢迎登录</view>
			<u-form  ref="uForm">
						<u-form-item label="用户名" prop="name" label-width="120" >
							<u-input v-model="form.account" placeholder="请输入用户名或手机号"/>
						</u-form-item>
						<u-form-item label="密码" prop="password" label-width="120">
							<u-input v-model="form.password"  type="password" placeholder="请输入密码" />
						</u-form-item>
			</u-form>
			<u-button @click="submit" style="margin-top: 30px;">提交</u-button>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{
					account:'',
					password:''
				}
			}
		},
		onLoad() {
			  // var list = ["a","b","c"];
			  // var start = 1;
     //          var i = list.length - start;
			  // //alert(i);
     //          var ret = new Array(i);
			  // console.log(ret);
     //          while (i--) {
     //              alert(i);
     //            ret[i] = list[i + start];
     //          }
            
		},
		computed: {
		},
		methods: {
			submit() {
				let that = this;
				if(!this.form.account){
					this.$refs.uToast.show({
										title: '用户名不能为空',
										
									})
					return false;
				}
				if(!this.form.password){
						this.$refs.uToast.show({
							title: '密码不能为空',				
						})
						return false;
				}
				//登录
				let form = this.form
				this.$u.post('api/user/login', form).then(res => {	
							let userinfo =  res.userinfo;
							uni.setStorageSync('userinfo', userinfo);
							uni.setStorageSync('token', userinfo.token);
							uni.redirectTo({
								url: '/pages/user/index'
							})	  
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff;
	}
	
.wrap {
	font-size: 28rpx;
	overflow: hidden;
	.content {
		width: 80%;
		margin: 180rpx auto 0;
		.title {
			text-align: left;
			font-size: 60rpx;
			font-weight: 500;
			margin-bottom: 100rpx;
		}
		input {
			text-align: left;
			margin-bottom: 10rpx;
			padding-bottom: 6rpx;
		}
		.tips {
			color: $u-type-info;
			margin-bottom: 60rpx;
			margin-top: 8rpx;
		}
		
	}

}

</style>
